﻿using Ninject;
using System;

namespace Nx.ViewModels
{
    public class ViewModelFactory : IViewModelFactory
    {
        private readonly IKernel container;

        public ViewModelFactory(IKernel container)
        {
            this.container = container;
        }

        public T CreateViewModel<T>() where T : ViewModelBase
        {
            return container.Get<T>();
        }

        public ViewModelBase CreateViewModel(Type viewModelType)
        {
            var viewModelObject = container.Get(viewModelType);
            return (ViewModelBase)viewModelObject;
        }

        public static T CreateViewModel<T>(IKernel externalContainer) where T : ViewModelBase
        {
            return externalContainer.Get<T>();
        }
    }
}
